home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / ATARI / ATARI.C next >
C/C++ Source or Header  |  1996-04-19  |  26KB  |  711 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   atari.c
  4.  
  5.   Atari-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   Contains:  readdir()
  8.              do_wild()           <-- generic enough to put in fileio.c?
  9.              mapattr()
  10.              mapname()
  11.              checkdir()
  12.              mkdir()
  13.              close_outfile()
  14.              version()
  15.  
  16.   Due to the amazing MiNT library being very, very close to BSD unix's
  17.   library, I'm using the unix.c as a base for this.  Note:  If you're not
  18.   going to compile this with the MiNT libraries (for GNU C, Turbo C, Pure C,
  19.   Lattice C, or Heat & Serve C), you're going to be in for some nasty work.
  20.   Most of the modifications in this file were made by Chris Herborth
  21.   (cherborth@semprini.waterloo-rdp.on.ca) and /should/ be marked with [cjh].
  22.  
  23.   ---------------------------------------------------------------------------*/
  24.  
  25.  
  26. #define UNZIP_INTERNAL
  27. #include "unzip.h"
  28. #include <dirent.h>            /* MiNTlibs has dirent [cjh] */
  29.  
  30. static int created_dir;        /* used in mapname(), checkdir() */
  31. static int renamed_fullpath;   /* ditto */
  32.  
  33.  
  34. #ifndef SFX
  35.  
  36. /**********************/
  37. /* Function do_wild() */   /* for porting:  dir separator; match(ignore_case) */
  38. /**********************/
  39.  
  40. char *do_wild(__G__ wildspec)
  41.     __GDEF
  42.     char *wildspec;         /* only used first time on a given dir */
  43. {
  44.     static DIR *dir = (DIR *)NULL;
  45.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  46.     static int firstcall=TRUE, have_dirname, dirnamelen;
  47.     struct dirent *file;
  48.  
  49.  
  50.     /* Even when we're just returning wildspec, we *always* do so in
  51.      * matchname[]--calling routine is allowed to append four characters
  52.      * to the returned string, and wildspec may be a pointer to argv[].
  53.      */
  54.     if (firstcall) {        /* first call:  must initialize everything */
  55.         firstcall = FALSE;
  56.  
  57.         /* break the wildspec into a directory part and a wildcard filename */
  58.         if ((wildname = strrchr(wildspec, '/')) == (char *)NULL) {
  59.             dirname = ".";
  60.             dirnamelen = 1;
  61.             have_dirname = FALSE;
  62.             wildname = wildspec;
  63.         } else {
  64.             ++wildname;     /* point at character after '/' */
  65.             dirnamelen = wildname - wildspec;
  66.             if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
  67.                 Info(slide, 0x201, ((char *)slide,
  68.                   "warning:  can't allocate wildcard buffers\n"));
  69.                 strcpy(matchname, wildspec);
  70.                 return matchname;   /* but maybe filespec was not a wildcard */
  71.             }
  72.             strncpy(dirname, wildspec, dirnamelen);
  73.             dirname[dirnamelen] = '\0';   /* terminate for strcpy below */
  74.             have_dirname = TRUE;
  75.         }
  76.  
  77.         if ((dir = opendir(dirname)) != (DIR *)NULL) {
  78.             while ((file = readdir(dir)) != (struct dirent *)NULL) {
  79.                 if (file->d_name[0] == '.' && wildname[0] != '.')
  80.                     continue;  /* Unix:  '*' and '?' do not match leading dot */
  81.                     /* Need something here for TOS filesystem? [cjh] */
  82.                 if (match(file->d_name, wildname, 0)) {  /* 0 == case sens. */
  83.                     if (have_dirname) {
  84.                         strcpy(matchname, dirname);
  85.                         strcpy(matchname+dirnamelen, file->d_name);
  86.                     } else
  87.                         strcpy(matchname, file->d_name);
  88.                     return matchname;
  89.                 }
  90.             }
  91.             /* if we get to here directory is exhausted, so close it */
  92.             closedir(dir);
  93.             dir = (DIR *)NULL;
  94.         }
  95.  
  96.         /* return the raw wildspec in case that works (e.g., directory not
  97.          * searchable, but filespec was not wild and file is readable) */
  98.         strcpy(matchname, wildspec);
  99.         return matchname;
  100.     }
  101.  
  102.     /* last time through, might have failed opendir but returned raw wildspec */
  103.     if (dir == (DIR *)NULL) {
  104.         firstcall = TRUE;  /* nothing left to try--reset for new wildspec */
  105.         if (have_dirname)
  106.             free(dirname);
  107.         return (char *)NULL;
  108.     }
  109.  
  110.     /* If we've gotten this far, we've read and matched at least one entry
  111.      * successfully (in a previous call), so dirname has been copied into
  112.      * matchname already.
  113.      */
  114.     while ((file = readdir(dir)) != (struct dirent *)NULL)
  115.         /* May need special TOS handling here. [cjh] */
  116.         if (match(file->d_name, wildname, 0)) {   /* 0 == don't ignore case */
  117.             if (have_dirname) {
  118.                 /* strcpy(matchname, dirname); */
  119.                 strcpy(matchname+dirnamelen, file->d_name);
  120.             } else
  121.                 strcpy(matchname, file->d_name);
  122.             return matchname;
  123.         }
  124.  
  125.     closedir(dir);     /* have read at least one dir entry; nothing left */
  126.     dir = (DIR *)NULL;
  127.     firstcall = TRUE;  /* reset for new wildspec */
  128.     if (have_dirname)
  129.         free(dirname);
  130.     return (char *)NULL;
  131.  
  132. } /* end function do_wild() */
  133.  
  134. #endif /* !SFX */
  135.  
  136.  
  137.  
  138.  
  139.  
  140. /**********************/
  141. /* Function mapattr() */
  142. /**********************/
  143.  
  144. int mapattr(__G)
  145.     __GDEF
  146. {
  147.     ulg tmp = G.crec.external_file_attributes;
  148.  
  149.     switch (G.pInfo->hostnum) {
  150.         case UNIX_:
  151.         case ATARI_:
  152.             /* minix filesystem under MiNT on Atari [cjh] */
  153.         case VMS_:
  154.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  155.             return 0;
  156.         case AMIGA_:
  157.             tmp = (unsigned)(tmp>>17 & 7);   /* Amiga RWE bits */
  158.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  159.             break;
  160.         /* all remaining cases:  expand MSDOS read-only bit into write perms */
  161.         case FS_FAT_:
  162.         case FS_HPFS_:
  163.         case FS_NTFS_:
  164.         case MAC_:
  165.         case TOPS20_:
  166.         default:
  167.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  168.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  169.             break;
  170.     } /* end switch (host-OS-created-by) */
  171.  
  172.     /* for originating systems with no concept of "group," "other," "system": */
  173.     umask( (int)(tmp=umask(0)) );    /* apply mask to expanded r/w(/x) perms */
  174.     G.pInfo->file_attr &= ~tmp;
  175.  
  176.     return 0;
  177.  
  178. } /* end function mapattr() */
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /************************/
  185. /*  Function mapname()  */
  186. /************************/
  187.  
  188. int mapname(__G__ renamed)   /* return 0 if no error, 1 if caution (filename */
  189.     __GDEF                   /* truncated), 2 if warning (skip file because  */
  190.     int renamed;             /* dir doesn't exist), 3 if error (skip file),  */
  191.                              /* 10 if no memory (skip file)                  */
  192. {
  193.     char pathcomp[FILNAMSIZ];    /* path-component buffer */
  194.     char *pp, *cp=(char *)NULL;  /* character pointers */
  195.     char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  196.     int quote = FALSE;           /* flags */
  197.     int error = 0;
  198.     register unsigned workch;    /* hold the character being tested */
  199.  
  200.  
  201. /*---------------------------------------------------------------------------
  202.     Initialize various pointers and counters and stuff.
  203.   ---------------------------------------------------------------------------*/
  204.  
  205.     if (G.pInfo->vollabel)
  206.         return IZ_VOL_LABEL;    /* can't set disk volume labels in Unix */
  207.  
  208.     /* can create path as long as not just freshening, or if user told us */
  209.     G.create_dirs = (!G.fflag || renamed);
  210.  
  211.     created_dir = FALSE;        /* not yet */
  212.  
  213.     /* user gave full pathname:  don't prepend rootpath */
  214.     renamed_fullpath = (renamed && (*G.filename == '/'));
  215.  
  216.     if (checkdir(__G__ (char *)NULL, INIT) == 10)
  217.         return 10;              /* initialize path buffer, unless no memory */
  218.  
  219.     *pathcomp = '\0';           /* initialize translation buffer */
  220.     pp = pathcomp;              /* point to translation buffer */
  221.     if (G.jflag)                /* junking directories */
  222.         cp = (char *)strrchr(G.filename, '/');
  223.     if (cp == (char *)NULL)     /* no '/' or not junking dirs */
  224.         cp = G.filename;        /* point to internal zipfile-member pathname */
  225.     else
  226.         ++cp;                   /* point to start of last component of path */
  227.  
  228. /*---------------------------------------------------------------------------
  229.     Begin main loop through characters in filename.
  230.   ---------------------------------------------------------------------------*/
  231.  
  232.     while ((workch = (uch)*cp++) != 0) {
  233.  
  234.         if (quote) {                 /* if character quoted, */
  235.             *pp++ = (char)workch;    /*  include it literally */
  236.             quote = FALSE;
  237.         } else
  238.             switch (workch) {
  239.             case '/':             /* can assume -j flag not given */
  240.                 *pp = '\0';
  241.                 if ((error = checkdir(__G__ pathcomp, APPEND_DIR)) > 1)
  242.                     return error;
  243.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  244.                 lastsemi = (char *)NULL; /* leave directory semi-colons alone */
  245.                 break;
  246.  
  247.             case ';':             /* VMS version (or DEC-20 attrib?) */
  248.                 lastsemi = pp;         /* keep for now; remove VMS ";##" */
  249.                 *pp++ = (char)workch;  /*  later, if requested */
  250.                 break;
  251.  
  252.             case '\026':          /* control-V quote for special chars */
  253.                 quote = TRUE;     /* set flag for next character */
  254.                 break;
  255.  
  256. #ifdef MTS
  257.             case ' ':             /* change spaces to underscore under */
  258.                 *pp++ = '_';      /*  MTS; leave as spaces under Unix */
  259.                 break;
  260. #endif
  261.  
  262.             default:
  263.                 /* allow European characters in filenames: */
  264.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  265.                     *pp++ = (char)workch;
  266.             } /* end switch */
  267.  
  268.     } /* end while loop */
  269.  
  270.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  271.  
  272.     /* if not saving them, remove VMS version numbers (appended ";###") */
  273.     if (!G.V_flag && lastsemi) {
  274.         pp = lastsemi + 1;
  275.         while (isdigit((uch)(*pp)))
  276.             ++pp;
  277.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  278.             *lastsemi = '\0';
  279.     }
  280.  
  281. /*---------------------------------------------------------------------------
  282.     Report if directory was created (and no file to create:  filename ended
  283.     in '/'), check name to be sure it exists, and combine path and name be-
  284.     fore exiting.
  285.   ---------------------------------------------------------------------------*/
  286.  
  287.     if (G.filename[strlen(G.filename) - 1] == '/') {
  288.         checkdir(__G__ G.filename, GETPATH);
  289.         if (created_dir && QCOND2) {
  290.             Info(slide, 0, ((char *)slide, "   creating: %s\n", G.filename));
  291.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  292.         }
  293.         return 2;   /* dir existed already; don't look for data to extract */
  294.     }
  295.  
  296.     if (*pathcomp == '\0') {
  297.         Info(slide, 1, ((char *)slide, "mapname:  conversion of %s failed\n",
  298.           G.filename));
  299.         return 3;
  300.     }
  301.  
  302.     checkdir(__G__ pathcomp, APPEND_NAME);   /* returns 1 if truncated: care? */
  303.     checkdir(__G__ G.filename, GETPATH);
  304.  
  305.     return error;
  306.  
  307. } /* end function mapname() */
  308.  
  309.  
  310.  
  311.  
  312. #if 0  /*========== NOTES ==========*/
  313.  
  314.   extract-to dir:      a:path/
  315.   buildpath:           path1/path2/ ...   (NULL-terminated)
  316.   pathcomp:                filename
  317.  
  318.   mapname():
  319.     loop over chars in zipfile member name
  320.       checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  321.         (d:/tmp/unzip/)                    (disk:[tmp.unzip.)
  322.         (d:/tmp/unzip/jj/)                 (disk:[tmp.unzip.jj.)
  323.         (d:/tmp/unzip/jj/temp/)            (disk:[tmp.unzip.jj.temp.)
  324.     finally add filename itself and check for existence? (could use with rename)
  325.         (d:/tmp/unzip/jj/temp/msg.outdir)  (disk:[tmp.unzip.jj.temp]msg.outdir)
  326.     checkdir(name, COPYFREE)     -->  copy path to name and free space
  327.  
  328. #endif /* 0 */
  329.  
  330.  
  331.  
  332.  
  333. /***********************/
  334. /* Function checkdir() */
  335. /***********************/
  336.  
  337. int checkdir(__G__ pathcomp, flag)
  338.     __GDEF
  339.     char *pathcomp;
  340.     int flag;
  341. /*
  342.  * returns:  1 - (on APPEND_NAME) truncated filename
  343.  *           2 - path doesn't exist, not allowed to create
  344.  *           3 - path doesn't exist, tried to create and failed; or
  345.  *               path exists and is not a directory, but is supposed to be
  346.  *           4 - path is too long
  347.  *          10 - can't allocate memory for filename buffers
  348.  */
  349. {
  350.     static int rootlen = 0;   /* length of rootpath */
  351.     static char *rootpath;    /* user's "extract-to" directory */
  352.     static char *buildpath;   /* full path (so far) to extracted file */
  353.     static char *end;         /* pointer to end of buildpath ('\0') */
  354.  
  355. #   define FN_MASK   7
  356. #   define FUNCTION  (flag & FN_MASK)
  357.  
  358.  
  359.  
  360. /*---------------------------------------------------------------------------
  361.     APPEND_DIR:  append the path component to the path being built and check
  362.     for its existence.  If doesn't exist and we are creating directories, do
  363.     so for this one; else signal success or error as appropriate.
  364.   ---------------------------------------------------------------------------*/
  365.  
  366.     if (FUNCTION == APPEND_DIR) {
  367.         int too_long = FALSE;
  368. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  369. #ifdef SHORT_NAMES
  370.         char *old_end = end;
  371. #endif
  372.  
  373.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  374.         while ((*end = *pathcomp++) != '\0')
  375.             ++end;
  376. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  377. #ifdef SHORT_NAMES   /* path components restricted to 14 chars, typically */
  378.         if ((end-old_end) > FILENAME_MAX)  /* GRR:  proper constant? */
  379.             *(end = old_end + FILENAME_MAX) = '\0';
  380. #endif
  381.  
  382.         /* GRR:  could do better check, see if overrunning buffer as we go:
  383.          * check end-buildpath after each append, set warning variable if
  384.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  385.          * appending.  Clear variable when begin new path. */
  386.  
  387.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  388.             too_long = TRUE;                /* check if extracting directory? */
  389.         if (stat(buildpath, &G.statbuf)) {  /* path doesn't exist */
  390.             if (!G.create_dirs) { /* told not to create (freshening) */
  391.                 free(buildpath);
  392.                 return 2;         /* path doesn't exist:  nothing to do */
  393.             }
  394.             if (too_long) {
  395.                 Info(slide, 1, ((char *)slide,
  396.                   "checkdir error:  path too long: %s\n", buildpath));
  397.                 free(buildpath);
  398.                 return 4;         /* no room for filenames:  fatal */
  399.             }
  400.             if (mkdir(buildpath, 0777) == -1) {   /* create the directory */
  401.                 Info(slide, 1, ((char *)slide,
  402.                   "checkdir error:  can't create %s\n\
  403.                  unable to process %s.\n", buildpath, G.filename));
  404.                 free(buildpath);
  405.                 return 3;      /* path didn't exist, tried to create, failed */
  406.             }
  407.             created_dir = TRUE;
  408.         } else if (!S_ISDIR(G.statbuf.st_mode)) {
  409.             Info(slide, 1, ((char *)slide,
  410.               "checkdir error:  %s exists but is not directory\n\
  411.                  unable to process %s.\n", buildpath, G.filename));
  412.             free(buildpath);
  413.             return 3;          /* path existed but wasn't dir */
  414.         }
  415.         if (too_long) {
  416.             Info(slide, 1, ((char *)slide,
  417.               "checkdir error:  path too long: %s\n", buildpath));
  418.             free(buildpath);
  419.             return 4;         /* no room for filenames:  fatal */
  420.         }
  421.         *end++ = '/';
  422.         *end = '\0';
  423.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  424.         return 0;
  425.  
  426.     } /* end if (FUNCTION == APPEND_DIR) */
  427.  
  428. /*---------------------------------------------------------------------------
  429.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  430.     buildpath.
  431.   ---------------------------------------------------------------------------*/
  432.  
  433.     if (FUNCTION == GETPATH) {
  434.         strcpy(pathcomp, buildpath);
  435.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  436.         free(buildpath);
  437.         buildpath = end = (char *)NULL;
  438.         return 0;
  439.     }
  440.  
  441. /*---------------------------------------------------------------------------
  442.     APPEND_NAME:  assume the path component is the filename; append it and
  443.     return without checking for existence.
  444.   ---------------------------------------------------------------------------*/
  445.  
  446.     if (FUNCTION == APPEND_NAME) {
  447. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  448. #ifdef SHORT_NAMES
  449.         char *old_end = end;
  450. #endif
  451.  
  452.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  453.         while ((*end = *pathcomp++) != '\0') {
  454.             ++end;
  455. /* SHORT_NAMES required for TOS, but it has to co-exist for minix fs... [cjh] */
  456. #ifdef SHORT_NAMES  /* truncate name at 14 characters, typically */
  457.             if ((end-old_end) > FILENAME_MAX)      /* GRR:  proper constant? */
  458.                 *(end = old_end + FILENAME_MAX) = '\0';
  459. #endif
  460.             if ((end-buildpath) >= FILNAMSIZ) {
  461.                 *--end = '\0';
  462.                 Info(slide, 0x201, ((char *)slide,
  463.                   "checkdir warning:  path too long; truncating\n\
  464.                    %s\n                -> %s\n", G.filename, buildpath));
  465.                 return 1;   /* filename truncated */
  466.             }
  467.         }
  468.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  469.         return 0;  /* could check for existence here, prompt for new name... */
  470.     }
  471.  
  472. /*---------------------------------------------------------------------------
  473.     INIT:  allocate and initialize buffer space for the file currently being
  474.     extracted.  If file was renamed with an absolute path, don't prepend the
  475.     extract-to path.
  476.   ---------------------------------------------------------------------------*/
  477.  
  478. /* GRR:  for VMS and TOPS-20, add up to 13 to strlen */
  479.  
  480.     if (FUNCTION == INIT) {
  481.         Trace((stderr, "initializing buildpath to "));
  482.         if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1)) ==
  483.             (char *)NULL)
  484.             return 10;
  485.         if ((rootlen > 0) && !renamed_fullpath) {
  486.             strcpy(buildpath, rootpath);
  487.             end = buildpath + rootlen;
  488.         } else {
  489.             *buildpath = '\0';
  490.             end = buildpath;
  491.         }
  492.         Trace((stderr, "[%s]\n", buildpath));
  493.         return 0;
  494.     }
  495.  
  496. /*---------------------------------------------------------------------------
  497.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  498.     sary; else assume it's a zipfile member and return.  This path segment
  499.     gets used in extracting all members from every zipfile specified on the
  500.     command line.
  501.   ---------------------------------------------------------------------------*/
  502.  
  503. #if (!defined(SFX) || defined(SFX_EXDIR))
  504.     if (FUNCTION == ROOT) {
  505.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  506.         if (pathcomp == (char *)NULL) {
  507.             rootlen = 0;
  508.             return 0;
  509.         }
  510.         if ((rootlen = strlen(pathcomp)) > 0) {
  511.             if (pathcomp[rootlen-1] == '/') {
  512.                 pathcomp[--rootlen] = '\0';
  513.             }
  514.             if (rootlen > 0 && (stat(pathcomp, &G.statbuf) ||
  515.                 !S_ISDIR(G.statbuf.st_mode)))       /* path does not exist */
  516.             {
  517.                 if (!G.create_dirs /* || iswild(pathcomp) */ ) {
  518.                     rootlen = 0;
  519.                     return 2;   /* skip (or treat as stored file) */
  520.                 }
  521.                 /* create the directory (could add loop here to scan pathcomp
  522.                  * and create more than one level, but why really necessary?) */
  523.                 if (mkdir(pathcomp, 0777) == -1) {
  524.                     Info(slide, 1, ((char *)slide,
  525.                       "checkdir:  can't create extraction directory: %s\n",
  526.                       pathcomp));
  527.                     rootlen = 0;   /* path didn't exist, tried to create, and */
  528.                     return 3;  /* failed:  file exists, or 2+ levels required */
  529.                 }
  530.             }
  531.             if ((rootpath = (char *)malloc(rootlen+2)) == (char *)NULL) {
  532.                 rootlen = 0;
  533.                 return 10;
  534.             }
  535.             strcpy(rootpath, pathcomp);
  536.             rootpath[rootlen++] = '/';
  537.             rootpath[rootlen] = '\0';
  538.             Trace((stderr, "rootpath now = [%s]\n", rootpath));
  539.         }
  540.         return 0;
  541.     }
  542. #endif /* !SFX || SFX_EXDIR */
  543.  
  544. /*---------------------------------------------------------------------------
  545.     END:  free rootpath, immediately prior to program exit.
  546.   ---------------------------------------------------------------------------*/
  547.  
  548.     if (FUNCTION == END) {
  549.         Trace((stderr, "freeing rootpath\n"));
  550.         if (rootlen > 0)
  551.             free(rootpath);
  552.         return 0;
  553.     }
  554.  
  555.     return 99;  /* should never reach */
  556.  
  557. } /* end function checkdir() */
  558.  
  559.  
  560.  
  561.  
  562. /****************************/
  563. /* Function close_outfile() */
  564. /****************************/
  565.  
  566. void close_outfile(__G)    /* GRR: change to return PK-style warning level */
  567.     __GDEF
  568. {
  569.     ztimbuf tp;
  570.  
  571. /*---------------------------------------------------------------------------
  572.     If symbolic links are supported, allocate a storage area, put the uncom-
  573.     pressed "data" in it, and create the link.  Since we know it's a symbolic
  574.     link to start with, we shouldn't have to worry about overflowing unsigned
  575.     ints with unsigned longs.
  576.   ---------------------------------------------------------------------------*/
  577.  
  578.     /* symlinks allowed on minix filesystems [cjh]
  579.      * Hopefully this will work properly... We won't bother to try if
  580.      * MiNT isn't present; the symlink should fail if we're on a TOS
  581.      * filesystem.
  582.      * BUG: should we copy the original file to the "symlink" if the
  583.      *      link fails?
  584.      */
  585.     if (G.symlnk) {
  586.         unsigned ucsize = (unsigned)G.lrec.ucsize;
  587.         char *linktarget = (char *)malloc((unsigned)G.lrec.ucsize+1);
  588.  
  589.         fclose(G.outfile);                      /* close "data" file... */
  590.         G.outfile = fopen(G.filename, FOPR);    /* ...and reopen for reading */
  591.         if (!linktarget || (fread(linktarget, 1, ucsize, G.outfile) !=
  592.                             (int)ucsize)) {
  593.             Info(slide, 0x201, ((char *)slide,
  594.               "warning:  symbolic link (%s) failed\n", G.filename));
  595.             if (linktarget)
  596.                 free(linktarget);
  597.             fclose(G.outfile);
  598.             return;
  599.         }
  600.         fclose(G.outfile);                  /* close "data" file for good... */
  601.         unlink(G.filename);                 /* ...and delete it */
  602.         linktarget[ucsize] = '\0';
  603.         Info(slide, 0, ((char *)slide, "-> %s ", linktarget));
  604.         if (symlink(linktarget, G.filename))  /* create the real link */
  605.             perror("symlink error");
  606.         free(linktarget);
  607.         return;                             /* can't set time on symlinks */
  608.     }
  609.  
  610.     fclose(G.outfile);
  611.  
  612. /*---------------------------------------------------------------------------
  613.     Convert from MSDOS-format local time and date to Unix-format 32-bit GMT
  614.     time:  adjust base year from 1980 to 1970, do usual conversions from
  615.     yy/mm/dd hh:mm:ss to elapsed seconds, and account for timezone and day-
  616.     light savings time differences.
  617.   ---------------------------------------------------------------------------*/
  618.  
  619. #ifdef USE_EF_UX_TIME
  620.     if (G.extra_field &&
  621.         ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length,
  622.                          &tp, NULL) > 0) {
  623.         TTrace((stderr, "\nclose_outfile:  Unix e.f. access time = %ld\n",
  624.           tp.actime));
  625.         TTrace((stderr, "close_outfile:  Unix e.f. modif. time = %ld\n",
  626.           tp.modtime));
  627.     } else {
  628.         tp.actime = tp.modtime = dos_to_unix_time(G.lrec.last_mod_file_date,
  629.                                                   G.lrec.last_mod_file_time);
  630.  
  631.         TTrace((stderr, "\nclose_outfile:  modification/access times = %ld\n",
  632.           tp.modtime));
  633.     }
  634. #else /* !USE_EF_UX_TIME */
  635.     tp.actime = tp.modtime = dos_to_unix_time(G.lrec.last_mod_file_date,
  636.                                               G.lrec.last_mod_file_time);
  637.  
  638.     TTrace((stderr, "\nclose_outfile:  modification/access times = %ld\n",
  639.       tp.modtime));
  640. #endif /* ?USE_EF_UX_TIME */
  641.  
  642.     /* set the file's access and modification times */
  643.     if (utime(G.filename, &tp))
  644.         Info(slide, 0x201, ((char *)slide,
  645.           "warning:  can't set the time for %s\n", G.filename));
  646.  
  647. /*---------------------------------------------------------------------------
  648.     Change the file permissions from default ones to those stored in the
  649.     zipfile.
  650.   ---------------------------------------------------------------------------*/
  651.  
  652. #ifndef NO_CHMOD
  653.     if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  654.             perror("chmod (file attributes) error");
  655. #endif
  656.  
  657. } /* end function close_outfile() */
  658.  
  659.  
  660.  
  661.  
  662. #ifndef SFX
  663.  
  664. /************************/
  665. /*  Function version()  */
  666. /************************/
  667.  
  668. void version(__G)
  669.     __GDEF
  670. {
  671. #ifdef __TURBOC__
  672.     char buf[40];
  673. #endif
  674.  
  675.     sprintf((char *)slide, LoadFarString(CompiledWith),
  676.  
  677. #ifdef __GNUC__
  678.       "gcc ", __VERSION__,
  679. #else
  680. #  if 0
  681.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  682. #  else
  683. #  ifdef __TURBOC__
  684.       "Turbo C", (sprintf(buf, " (0x%04x = %d)", __TURBOC__, __TURBOC__), buf),
  685. #  else
  686.       "unknown compiler", "",
  687. #  endif
  688. #  endif
  689. #endif
  690.  
  691. #ifdef __MINT__
  692.       "Atari TOS/MiNT",
  693. #else
  694.       "Atari TOS",
  695. #endif
  696.  
  697.       " (Atari ST/TT/Falcon030)",
  698.  
  699. #ifdef __DATE__
  700.       " on ", __DATE__
  701. #else
  702.       "", ""
  703. #endif
  704.     );
  705.  
  706.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  707.  
  708. } /* end function version() */
  709.  
  710. #endif /* !SFX */
  711.